package org.jeik.beackBeans.contents;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeik.beackBeans.BeansBase;
import org.jeik.controllers.MsgsController;
import org.jeik.controllers.NavigationController;
import org.jeik.controllers.NavigationRule;
import org.jeik.data.dao.DataException;
import org.jeik.data.models.Page;
import org.jeik.data.models.ServiceParent;
import org.jeik.data.services.EmbassyServicesService;
import org.jeik.data.services.PageContentsService;
import org.jeik.data.models.Service;

/**
 * 
 * 
 * @author AAsha
 *
 */
public class PageContentsBean extends BeansBase {

	private static final long serialVersionUID = 1L;

	private Map<String,Page> contents = new HashMap<String, Page>();
	
	private List<ServiceParent> serviceParents = new ArrayList<ServiceParent>();
	
	private List<Service> services = new ArrayList<Service>();
	
	/**
	 * 
	 */
	public PageContentsBean() {
	}
	
	public void refreshCache(){
		loadContentPages();
		loadServiceParents();
		loadServices();
	}
	
	/**
	 * 
	 */
	public void refreshCacheAndNavigateHome(){
		refreshCache();
		
		MsgsController.addInfoMessage("تم اعادة تحميل البيانات بنجاح");
		
		NavigationController.navigate(NavigationRule.HOME);
	}
	
	/**
	 * 
	 */
	public void loadContentPages(){
		try {
			contents = PageContentsService.getInstance().loadContentPages();
		} catch (DataException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 */
	public void loadServiceParents(){
		try {
			serviceParents = EmbassyServicesService.getInstance().loadEmbassyServicesParents();
		} catch (DataException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 */
	public void loadServices(){
		try {
			services = EmbassyServicesService.getInstance().loadEmbassyServices();
		} catch (DataException e) {
			e.printStackTrace();
		}
	}
	
	public Map<String, Page> getContents() {
		return contents;
	}

	public void setContents(Map<String, Page> contents) {
		this.contents = contents;
	}

	public List<Service> getServices() {
		return services;
	}

	public void setServices(List<Service> services) {
		this.services = services;
	}

	public List<ServiceParent> getServiceParents() {
		return serviceParents;
	}

	public void setServiceParents(List<ServiceParent> serviceParents) {
		this.serviceParents = serviceParents;
	}
	
}
